<template>
	<view class="shop">
		<!-- <view class="top">
			<image v-if="info.banner == null" src="/static/new/banner_01.png" mode=""></image>
			<image v-else :src="info.banner | getImg" mode=""></image>
		</view> -->
		<view class="header">
			<view class="header_left">
				<image :src="info.img | getImg" mode=""></image>
				<view class="bus_info">
					<text class="name">{{info.shop_name}}</text>
					<view class="address" @click="toAddress">
						<text>{{info.shop_address}}</text>
						<!-- <uni-icons type="forward"></uni-icons> -->
					</view>
				</view>
			</view>
			<view class="phonebox" @click="call">
				<uni-icons type="phone-filled" color="#ff0000"></uni-icons>
				<text>联系Ta</text>
			</view>
		</view>
		<!-- 
		<view class="info">
			<view class="infolist">
				<view class="left">
					营业时间
				</view>
				<view class="right">
					{{info.open_time}}
				</view>
			</view>
			<view class="infolist min_height_80">
				<view class="left">
					商家介绍
				</view>
				<view class="right">
					{{info.content}}
				</view>
			</view>
			<view class="infolist">
				<view class="left">
					商家图片
				</view>
				<view class="right">
					<image @click="show_img" v-for="(item,index) in info.goods_img" :key="index" :src="item | getImg"
						mode=""></image>
				</view>
			</view>
			<view class="infolist min_height_80">
				<view class="left">
					商家描述
				</view>
				<view class="right">
					{{info.main_project}}
				</view>
			</view>
			<view class="infolist min_height_80">
				<view class="left" @click="toPage(shop_url)">
					商家链接
				</view>
				<view class="right">

				</view>
			</view> -->
		<view class="goods-list">
			<view class="title">

			</view>
			<view class="product-list">
				<view class="product" v-for="(product,index) in goodsList" :key="index" @tap="toGoods(product)">
					<image mode="" :src="product.logo_url | getImg"></image>
					<view class="name">{{ product.name }}</view>
					<view class="info">
						<view class="price">￥{{ product.price }}</view>
						<view class="slogan">已售：{{ product.sell }}</view>
					</view>
				</view>
			</view>
			<view class="loading-text">{{loadingText}}</view>
		</view>
	</view>
</template>

<script>
	import {
		OfflineDetail,
		ShopGoods
	} from "@/api/api.js"

	export default {
		data() {
			return {
				phone: '',
				info: [],
				goodsList: [],
				loadingText: "正在加载...",
				shop_url: '',
				flag: true,
				page: 1,
				search: {
					sort: 22322
				}
			}
		},
		onLoad(e) {
			if (e.id) {
				this.ShopDetail(e.id)

			} else if (e.offid) {
				this.OfflineDetail(e.offid)
			}

		},
		//上拉加载，需要自己在page.json文件中配置"onReachBottomDistance"
		onReachBottom() {
			if (this.flag) {
				this.page++
				this.search.page = this.page
				this.GoodsList()
			}

		},
		methods: {
			//商品跳转
			toGoods(e) {
				uni.navigateTo({
					url: '/pages/goods/goods1?id=' + e.id
				});
			},
			GoodsList() {
				this.loadingText = "正在加载...";
				ShopGoods(this.search).then(res => {
					if (res.status == 0) {
						this.flag = false
						this.loadingText = "没有更多数据";
					} else {
						if (res.data.goods.length > 0) {
							this.goodsList = this.goodsList.concat(res.data.goods)
							this.loadingText = "上拉加载更多";
							this.flag = true
						} else {
							this.flag = false
							this.loadingText = "没有更多数据";
						}
					}
				})
			},
			toPage(url) {
				if (url) {
					uni.navigateTo({
						url
					})
				}

			},
			call() {
				uni.makePhoneCall({
					phoneNumber: info.phone
				})
			},
			toAddress() {
				uni.openLocation({
					latitude: Number(this.info.latitude),
					longitude: Number(this.info.longitude),
					address: this.info.shop_address,
					name: this.info.address_name,
					success: (res) => {
						console.log(res);
					},
					fail: (err) => {
						console.log(err);
					}
				})
			},
			show_img() {
				var arr = []
				for (var i = 0; i < this.info.goods_img.length; i++) {
					arr.push(getApp().globalData.data.websiteUrl + this.info.goods_img[i])
				}
				uni.previewImage({
					urls: arr
				})
			},
			ShopDetail(id) {
				ShopDetail({
					id: id
				}).then(res => {
					this.info = res.data
					this.info.goods_img = this.info.goods_img.split(',')
					this.shop_url = '../goodslist/goods-list?shop=' + this.info.id
					console.log(res);
				})
			},
			OfflineDetail(id) {
				OfflineDetail({
					id: id
				}).then(res => {
					this.info = res.data
					this.info.goods_img = this.info.goods_img.split(',')
					this.shop_url = '../goodslist/goods-list?offline=' + this.info.id
					// this.GoodsList(this.info.id)
					this.search.offline = this.info.id
					this.search.page = 1
					this.GoodsList()
					console.log(res);
				})
			},
			call() {
				uni.makePhoneCall({
					phoneNumber: this.info.phone
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #fff;
	}

	.top {
		image {
			width: 100%;
			height: 130px;
		}
	}

	.goods-list {

		// background-color: #f4f4f4;
		.title {
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 80upx;
			color: #f47825;
			font-size: 30upx;
			margin-top: 10upx;

			image {
				width: 30upx;
				height: 30upx;
			}
		}

		.loading-text {
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 60upx;
			color: #979797;
			font-size: 24upx;
		}

		.product-list {
			width: 92%;
			padding: 0 4% 3vw 4%;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			.product {
				width: 48%;
				border-radius: 20upx;
				background-color: #fff;
				margin: 0 0 15upx 0;
				box-shadow: 0upx 5upx 25upx rgba(0, 0, 0, 0.1);

				image {
					width: 100%;
					border-radius: 20upx 20upx 0 0;
					height: 160px;
				}

				.name {
					width: 92%;
					padding: 10upx 4%;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					text-align: justify;
					overflow: hidden;
					font-size: 30upx;
					padding-bottom: 0;
				}

				.info {
					display: flex;
					justify-content: space-between;
					align-items: flex-end;
					width: 92%;
					padding: 10upx 4% 10upx 4%;

					.price {
						color: #e65339;
						font-size: 30upx;
						font-weight: 600;
					}

					.slogan {
						color: #807c87;
						font-size: 24upx;
					}
				}
			}
		}
	}


	.header {
		display: flex;
		padding: 15px;
		box-sizing: border-box;
		justify-content: space-between;
		border-bottom: 1px solid #ccc;

		.bus_info {
			display: flex;
			width: 80%;
			flex-direction: column;
		}

		.header_left {
			display: flex;
			align-items: center;
		}

		image {
			width: 60px;
			height: 60px;
			border-radius: 5px;
		}

		.name {
			font-size: 15px;
			font-weight: bold;
			margin-left: 3%;
			// max-width: 70%;
		}

		.phonebox {
			display: flex;
			flex-direction: column;
			align-items: center;
			margin-top: 10px;
			width: 50px;

			text {
				font-size: 14px;
				color: #ff0000;
			}
		}

	}

	.address {
		padding: 0 3%;
		font-size: 12px;
		color: #999;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 4px;
	}

	.min_height_80 {
		min-height: 80px;
	}

	.info {
		.infolist {
			display: flex;
			padding: 0 5%;
			margin-top: 20px;
			font-size: 14px;

			.left {
				width: 25%;
			}

			.right {
				width: 75%;
				display: flex;
				flex-wrap: wrap;

				image {
					width: 32%;
					margin: 0 1%;
					height: 80px;
				}
			}
		}
	}
</style>
